<?php

namespace App\Admin\Extensions\Form;
use Encore\Admin\Form\Field;

class WangEditor  extends Field
{
    protected $view = 'admin.wang-editor';
    protected static $css = [
        '/packages/wangeditor/release/wangEditor.min.css',
    ];
    public static $js = [

        '/packages/wangeditor/release/wangEditor.min.js'

    ];
    public function render()
    {
        $name = $this->formatName($this->column);

        $this->script = <<<EOT

var E = window.wangEditor
var editor = new E('#{$this->id}');
editor.customConfig.zIndex = 0
editor.customConfig.uploadImgHeaders = {
    'X-CSRF-TOKEN': $('input[name="_token"]').val()
}
editor.customConfig.uploadImgServer = '/admin/api/upimage'
editor.customConfig.uploadFileName = 'wangpic[]'
editor.customConfig.onchange = function (html) {
    $('input[name=\'$name\']').val(html);
}
editor.create()

EOT;
        return parent::render();
    }
}